--非redis_manager节点call节点redis_manager下的服务
function CallRedisRpc(func, ...)
    local ok, res 
    if FRAME_CALL_TYPE==__CALL_TYPE_CLUSTER__ then 
        ok, res = cluster.call("redis", ".redis", func, ...)
    elseif REDIS_CALL_TYPE==__CALL_TYPE_SINGLE__ then 
        ok, res = skynet.call(".redis", 'lua', func, ...)
    end
    --error
    if not ok then 
        log.error("CallRedisRpc error func=", func)
    end

    return res
end

--redis_manager节点下服务之间的call
function CallRedis(func, ...)   
    local ok, res = skynet.call(".redis_tools", 'lua', func, ...)

    --error
    if not ok then 
        log.error("CallRedis error func=", func)
    end
    return res
end

--非mysql_manager节点call节点mysql_manager下的服务
function CallMysqlRpc(func, ...)
    log.info("CallMysqlRpc func=", func)
    local ok, res 
    if FRAME_CALL_TYPE==__CALL_TYPE_CLUSTER__ then 
        ok, res = cluster.call("mysql", ".mysql", func, ...)
    elseif REDIS_CALL_TYPE==__CALL_TYPE_SINGLE__ then 
        ok, res = skynet.call(".mysql", 'lua', func, ...)
    end
    --error
    if not ok then 
        log.error("CallMysqlRpc error func=", func)
        return res
    end

    return res
end

--mysql_manager节点下服务之间的call
function CallMysql(procedure)   
    log.info("CallMysql procedure=", procedure)
    local ok, res = skynet.call(".mysql_tools", 'lua', 'Call', procedure)
    --error
    if not ok then 
        log.error("CallMysql error func=", procedure)
        return 
    end
    return res
end

--非mysql_manager节点call短信服务
function CallShortMessageRpc(func, ...)   
    log.info("CallShortMessageRpc procedure=", procedure)
    local ok, res = cluster.call("mysql", ".short_message", func, ...)
    --error
    if not ok then 
        log.error("CallShortMessageRpc error func=", func)
        return 
    end
    return res
end

--发送PB消息给wg转发给agent
function SendPbMsgToWg(func, fd, msg, packId)   
    local connType = __CONN_TYPE_WEBSOCKET___
    local packName = g_packType[g_manager_node.wg][packId]..".MsgBody"
   
    local encodeMsg = PbEncode(packName, msg, packId)
    if encodeMsg==nil then
        log.error('encodeMsg faild :', packName )
        return 
    end

    if func=="call" then
        skynet.call('.wg', 'lua', 'SendMsg', __CONN_TYPE_WEBSOCKET___, fd, encodeMsg)
    elseif func=="send" then
        skynet.send('.wg', 'lua', 'SendMsg', __CONN_TYPE_WEBSOCKET___, fd, encodeMsg)
    end
end

--远程节点发送PB消息给wg转发给agent
function SendPbMsgToWgRpc(func, fd, msg, packId, node)   
    local connType = __CONN_TYPE_WEBSOCKET___
    local packName = g_packType[node][packId]..".MsgBody"
    local ret 

    local encodeMsg = PbEncode(packName, msg, packId)
    if encodeMsg==nil then
        log.error('encodeMsg faild :', packName )
        return 
    end

    if func=="call" then
        if FRAME_CALL_TYPE==__CALL_TYPE_CLUSTER__ then 
            ret = cluster.call('wg', '.wg', 'SendMsg', __CONN_TYPE_WEBSOCKET___, fd, encodeMsg)
        elseif REDIS_CALL_TYPE==__CALL_TYPE_SINGLE__ then 
            ret = skynet.call('.wg', 'lua', 'SendMsg', __CONN_TYPE_WEBSOCKET___, fd, encodeMsg)
        end
    elseif func=="send" then
        if FRAME_CALL_TYPE==__CALL_TYPE_CLUSTER__ then 
            cluster.send('wg', '.wg', 'SendMsg', __CONN_TYPE_WEBSOCKET___, fd, encodeMsg)
        elseif REDIS_CALL_TYPE==__CALL_TYPE_SINGLE__ then 
            skynet.send('.wg', 'lua', 'SendMsg', __CONN_TYPE_WEBSOCKET___, fd, encodeMsg)
        end
    end

    return ret
end

--wg管理节点下服务之间的send
function SendWg(fd, msgData)   
    skynet.send(".wg", 'lua', 'DispatchMsg', fd, msgData)
end

--hall
function CallConfig(func, ...)
    local ok, res = skynet.call(".service_handle_config", 'lua', func, ...)
    --error
    if not ok then 
        log.error("CallHall error func=", func)
    end

    return res
end

------------------------------------------------------------------------------------
--hall节点内部发pb消息
function SendHallPbMsg(func, fd, msg, packId)   
    local connType = __CONN_TYPE_WEBSOCKET___

    local packName = g_packType[g_manager_node.hall][packId]..".MsgBody"
    local encodeMsg = PbEncode(packName, msg, packId)
    if encodeMsg==nil then
        log.error('encodeMsg faild :', packName )
        return 
    end

    if func=="call" then
        skynet.call('.hall', 'lua', 'SendMsg', connType, fd, encodeMsg)
    elseif func=="send" then
        skynet.send('.hall', 'lua', 'SendMsg', connType, fd, encodeMsg)
    end
end

function SendGamePbMsg(func, fd, msg, packId)   
    local connType = __CONN_TYPE_WEBSOCKET___

    --[[
    local packName = g_packType[g_manager_node.game][packId]..".MsgBody"
    local encodeMsg = PbEncode(packName, msg, packId)
    if encodeMsg==nil then
        log.error('encodeMsg faild :', packName )
        return 
    end
    --]]

    if func=="call" then
        skynet.call('.game_ermj', 'lua', 'SendMsg', connType, fd, msg, packId)
    elseif func=="send" then
        skynet.send('.game_ermj', 'lua', 'SendMsg', connType, fd, msg, packId)
    end
end

--和.handle_agent_info 同一节点 下的服务调用
function CallAgentInfo(func, ...)
    log.info("CallAgentInfo func=", func)
    local ok, res = skynet.call(".service_agent_info", 'lua', func, ...)
    --error
    if not ok then 
        log.error("CallAgentInfo error func=", func)
        return 
    end

    return res
end